﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;

public partial class Controls_LeftRealestateMenu : Base_Controls
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.setField(Convert.ToInt32(this.Attributes["ID"]));
        if (!IsPostBack)
        {
            loadData();
            int category_id = Setting.getRequest(Request, "category_id", 27);
            DataTable objDT = BO_portal_categories.Search(category_id);
            if (objDT.Rows.Count > 0)
            {
                string script = "$(\"#td" + objDT.Rows[0]["PARENT_ID"].ToString() + "\").addClass('activeds');$(\"#td" + objDT.Rows[0]["PARENT_ID"].ToString() + "\").next().slideDown('slow');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Information", script, true);
            }
        }
    }

    protected void loadData()
    {
        DataTable objDT = BO_portal_categories.SelectByParent(base.Cid, 1);
        if (base.Lang)
        {
            foreach (DataRow row in objDT.Rows)
            {
                row["FULL_CATEGORY_NAME"] = row["FULL_CATEGORY_NAME_ENG"];
            }
        }
        rptMenu.DataSource = objDT;
        rptMenu.DataBind();
        for (int i = 0; i < rptMenu.Items.Count; i++)
        {
            RepeaterItem item = rptMenu.Items[i];
            Repeater rpt = (Repeater)item.FindControl("rptChild");
            if (rpt != null)
            {
                DataTable objG = loadChildren(objDT.Rows[i]["CATEGORY_ID"].ToString());
                if (objG.Rows.Count > 0)
                {
                    rpt.DataSource = objG;
                    rpt.DataBind();
                }
                else
                    rpt.Visible = false;
            }
        }
    }
    protected DataTable loadChildren(string parent_id)
    {
        DataTable objDT = BO_portal_categories.SelectByParent(Convert.ToInt32(parent_id), 1);
        if (base.Lang)
        {
            foreach (DataRow row in objDT.Rows)
            {
                row["FULL_CATEGORY_NAME"] = row["FULL_CATEGORY_NAME_ENG"];
            }
        }
        return objDT;
    }
}